home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.tar / ftp.whtech.com / datasheets and manuals / Hardware / WHT / scsi / dsr_sources_2_2001 / mkfdr < prev    next >
Text File  |  2006-10-19  |  12KB  |  546 lines

  1. ************************************************************
  2. *                                                          *
  3. *  MKFDR                                                   *
  4. *                                                          *
  5. *  This procedure will take in file information and        *
  6. *  create an FDR on disk and insert it into the parent     *
  7. *  directory.  If the file exists, its flags are checked   *
  8. *  for compatibility.                                      *
  9. *                                                          *
  10. *  Inputs:                                                 *
  11. *     MKFL3 - # of level 3 records in the file             *
  12. *     MKFRL - Record length                                *
  13. *     MKFRPS - # of records per sector                     *
  14. *     MKFEOF - End of File offset                          *
  15. *     MKFLAG - File flags                                  *
  16. *     MKFSZ  - Size of file in sectors                     *
  17. *                                !                         *
  18. *  Output:                                                 *
  19. *     R1 = status (0=success)                              *
  20. *                                                          *
  21. ************************************************************
  22.  
  23.  
  24. ************************************************************
  25. *                                                          *
  26. *  Revision history -                                      *
  27. *                                                          *
  28. *  10-19-95 - I am completely rewriting this routine       *
  29. *  because I didn't like how the old routine would have    *
  30. *  to scan the directory twice if a file didn't exist.     *
  31. *  I no longer call GETFDR in this routine.                *
  32. *                                                          *
  33. ************************************************************
  34.  
  35. MKFDR
  36.  
  37. * OK - first we will see if the file exists or not.
  38. *
  39.        LDCR @B02,4           Save return address
  40.        MOV  R11,@MKSR11
  41.  
  42. * See if the parent directory exists
  43. *
  44.        BL   @GETDDR
  45.        CI   R5,0
  46.        JNE  MKF1
  47.  
  48.        LI   R1,7             File Error
  49.        B    @MKFRT
  50.  
  51. MKF1
  52.        LDCR @B03,4
  53.        MOVB @22(R5),R1       Get # of files in directory
  54. * Lets read the FDIR
  55. *
  56.        MOV  @24(R5),R7
  57.        MOV  R6,R3
  58.        SRL  R3,8
  59.        SLA  R3,1
  60.        LDCR @B02,4
  61.        MOV  R7,@SFDRAU       Save AU of FDIR
  62.        LDCR @B04,4
  63.        MPY  @SAUTBL(R3),R7
  64.        LI   R2,SECBUF
  65.  
  66.        SRL  R8,1
  67.        JNC  MKF3
  68.        AI   R2,>100
  69. MKF3   SRL  R7,1
  70.        JNC  MKF4
  71.        AI   R8,>8000
  72. MKF4   LDCR @ZERO,4
  73.        BLWP @BANKIT
  74.        DATA SCSIRD
  75.        JNE  MKFERR
  76.  
  77. * Move the FDIR to another buffer
  78. *
  79.        LI   R4,DFDR
  80.        LI   R0,256
  81. MKF5   MOV  *R2+,R3
  82.        LDCR @B02,4
  83.        MOV  R3,*R4+
  84.        LDCR @ZERO,4
  85.        DECT R0
  86.        JNE  MKF5
  87.  
  88. * Copy the filename to FDIR
  89. *
  90.        LI   R2,NCB+39
  91.        LI   R3,FNCB
  92.        LDCR @B02,4
  93. MKF6   CB   *R2,@PERIOD
  94.        JEQ  MKF7
  95.        DEC  R2
  96.        CI   R2,NCB-1
  97.        JNE  MKF6
  98.  
  99. MKF7   INC  R2
  100. MKF7A  MOVB *R2+,R4
  101.        LDCR @ZERO,4
  102.        MOVB R4,*R3+
  103.        LDCR @B02,4
  104.        CB   *R2,@SPACE
  105.        JEQ  MKF8
  106.        CI   R2,NCB+40
  107.        JNE  MKF7A
  108.  
  109. MKF8   LDCR @ZERO,4
  110. MKF8A  CI   R3,FNCB+10
  111.        JEQ  MKF9
  112.        MOVB @SPACE,*R3+
  113.        JMP  MKF8A
  114.  
  115. MKF9
  116.  
  117. * Now set the bounds of our search.  If the directory is
  118. * empty, we can skip this part
  119. *
  120.        CLR  R0
  121.        SRL  R1,8
  122.        CI   R1,0
  123.        JEQ  MKF17
  124.  
  125.        DEC  R1
  126.  
  127. MKF10  MOV  R0,R10           Compute the midpoint
  128.        A    R1,R10
  129.        ANDI R10,>FFFE
  130.  
  131.        LDCR @B02,4
  132.        MOV  @DFDR(R10),R7
  133.  
  134.        MOV  R6,R3
  135.        SRL  R3,8
  136.        SLA  R3,1
  137.        LDCR @B04,4
  138.        MPY  @SAUTBL(R3),R7
  139.        LI   R2,SECBUF
  140.  
  141.        SRL  R8,1
  142.        JNC  MKF11
  143.        AI   R2,>100
  144. MKF11  SRL  R7,1
  145.        JNC  MKF12
  146.        AI   R8,>8000
  147. MKF12  LDCR @ZERO,4
  148.        BLWP @BANKIT
  149.        DATA SCSIRD
  150.        JNE  MKFERR
  151.  
  152. * OK, We got the FDR in the buffer.  Compare file names
  153. *
  154.        LI   R3,FNCB
  155.        LI   R9,10
  156. MKF13  C    *R2+,*R3+
  157.        JL   MKF14
  158.        JH   MKF15
  159.        DECT R9
  160.        JNE  MKF13
  161.  
  162. * The file exists!  Branch to a part of code that checks
  163. * the file type and protection.
  164.  
  165.        LDCR @B02,4
  166. *      MOV  @DFDR(R10),R10   Save AU of FDR
  167.        MOV  @DFDR(R10),@MKFAU1
  168.        B    @MKF30
  169.  
  170. MKF14  C    R0,R1
  171.        JEQ  MKF16
  172.        SRL  R10,1
  173.        MOV  R10,R0
  174.        INC  R0
  175.        JMP  MKF10
  176.  
  177. MKF15  C    R0,R1
  178.        JEQ  MKF17
  179.        SRL  R10,1
  180.        MOV  R10,R1
  181.        C    R0,R1
  182.        JEQ  MKF17
  183.        DEC  R1
  184.        JMP  MKF10
  185.  
  186. MKFERR LI   R1,6             Device Error
  187. MKFRT  LDCR @B02,4
  188.        MOV  @MKSR11,R11
  189.        RT
  190.  
  191.  
  192. MKF16  INC  R0
  193. MKF17  SLA  R0,1
  194.        AI   R0,DFDR
  195.  
  196. * Lets make sure we don't already have 127 files in
  197. * this directory before trying to create a new one
  198.  
  199.        LDCR @B03,4
  200.        CB   @B127,@22(R5)
  201.        JNE  MKF17A
  202.  
  203. MKF18  LI   R1,4         Out of space error
  204.        JMP  MKFRT
  205. MKF17A
  206.  
  207. * Let's allocate an AU to store the file's FDR and insert
  208. * it into the parent's FDIR
  209. *
  210.  
  211.        CLR  R3               Start at beginning
  212.        CLR  R7               No preferred AU
  213.        LI   R8,1             We want 1 AU
  214.        LDCR R3,0         Select RAM bank 0
  215. *      LDCR @ZERO,4
  216.        BLWP @ALLOC
  217.        JNE  MKFERR
  218.  
  219.        CI   R4,0
  220.        JEQ  MKF18            Out of space error
  221.  
  222. * Now insert the AU into the FDIR
  223. *
  224.        LDCR @B02,4
  225.        LI   R1,DFDR+252
  226. MKF19  C    R1,R0
  227.        JEQ  MKF20
  228.        MOV  @-2(R1),*R1
  229.        DECT R1
  230.        JMP  MKF19
  231.  
  232. MKF20  MOV  R5,*R0
  233.        MOV  R5,@MKFAU1       Save AU of FDR
  234.  
  235. * Now write the FDIR back out to disk.
  236. *
  237.        MOV  @SFDRAU,R7
  238.        LDCR @B04,4
  239.        MOV  R6,R3
  240.        SRL  R3,8
  241.        SLA  R3,1
  242.        MPY  @SAUTBL(R3),R7
  243.  
  244.        LI   R2,SECBUF
  245.        SRL  R8,1
  246.        JNC  MKF21
  247.        AI   R2,>100
  248. MKF21  SRL  R7,1
  249.        JNC  MKF22
  250.        AI   R8,>8000
  251. MKF22  LDCR @ZERO,4
  252.        BLWP @BANKIT
  253.        DATA SCSIRD
  254.        JNE  MKFERR
  255.  
  256.        LI   R3,DFDR
  257.        LI   R0,256
  258. MKF23  LDCR @B02,4
  259.        MOV  *R3+,R4
  260.        LDCR @ZERO,4
  261.        MOV  R4,*R2+
  262.        DECT R0
  263.        JNE  MKF23
  264.  
  265.        BLWP @BANKIT
  266.        DATA SCSIWT
  267.        JNE  MKFERR
  268.  
  269. * Now that we have the new FDIR written to disk, increment
  270. * the file counter in the parent DDR
  271. *
  272.  
  273.        BL   @GETDDR
  274.        LDCR @B03,4
  275.        AB   @B01,@22(R5)     Increment cache
  276.  
  277.        LDCR @B04,4
  278.        MOV  @SAVEAU,R7
  279.        MOV  R6,R3
  280.        SRL  R3,8
  281.        SLA  R3,1
  282.        MPY  @SAUTBL(R3),R7
  283.  
  284.        LI   R2,SECBUF
  285.        SRL  R8,1
  286.        JNC  MKF24
  287.        AI   R2,>100
  288. MKF24  SRL  R7,1
  289.        JNC  MKF25
  290.        AI   R8,>8000
  291. MKF25  LDCR @ZERO,4
  292.        BLWP @BANKIT
  293.        DATA SCSIRD
  294.        JNE  MKFERR
  295.  
  296. * now increment the file counter
  297.  
  298.        AB   @B01,@22(R2)
  299.  
  300. * And write back out to disk
  301.  
  302. MKF25C BLWP @BANKIT
  303.        DATA SCSIWT
  304.        JNE  MKFERR
  305.  
  306. * If this was the VIB, we must also write it out
  307. * in the copy
  308.  
  309.        CI   R8,0
  310.        JNE  MKF25B
  311.        CI   R7,0
  312.        JNE  MKF25B
  313.        AI   R8,16
  314.        JMP  MKF25C
  315. MKF25B
  316. * Now we will create an FDR in the DFDR buffer in bank 2
  317. * Start by filling in the file name
  318.  
  319.        LI   R1,DFDR
  320.        LI   R2,FNCB
  321.        LI   R0,10
  322. MKF25A LDCR @ZERO,4
  323.        MOV  *R2+,R3
  324.        LDCR @B02,4
  325.        MOV  R3,*R1+
  326.        DECT R0
  327.        JNE  MKF25A
  328.  
  329.        CLR  *R1+             Extended record length
  330.        MOVB @MKFLAG,*R1+     File flags
  331.        MOVB @MKFRPS,*R1+     Records per sector
  332.        CLR  *R1+             # of sectors allocated
  333.        MOVB @MKFEOF,*R1+     End of file offset
  334.        MOVB @MKFRL,*R1+      Record Length
  335.        MOV  @MKFL3,*R1+      # of level 3 records
  336.        CLR  *R1+             Creation date
  337.        CLR  *R1+
  338.        CLR  *R1+             Update date
  339.        CLR  *R1+
  340.        LI   R0,'FI'
  341.        MOV  R0,*R1+
  342.        CLR  *R1+             Parent FDR
  343.        CLR  *R1+             Offspring AU
  344.        CLR  *R1+             AU's allocated for FDR
  345.        MOV  @SFDRAU,*R1+     Pointer to FDIR
  346.        CLR  *R1+             Extended information
  347. MKF26  CLR  *R1+             Data chain pointers
  348.        CI   R1,DFDR+256
  349.        JNE  MKF26
  350.  
  351. * Now branch to a section of code that will allocate
  352. * all the AU's we need for the file
  353.  
  354.        B    @MKF40
  355.  
  356. ************************************************************
  357. *                                                          *
  358. *  The file already exists, so we have to check to make    *
  359. *  sure the file attribute match.  If they do, we will     *
  360. *  make sure we have enough AUs allocated and rewrite      *
  361. *  the FDR back to disk.                                   *
  362. *                                                          *
  363. ************************************************************
  364.  
  365.  
  366. MKF30
  367.  
  368. * Start by copying the FDR to the DFDR buffer in bank 2
  369.  
  370.        LI   R1,DFDR
  371.        AI   R2,-10           It still points to FDR
  372.        LI   R0,256
  373. MKF31  LDCR @ZERO,4
  374.        MOV  *R2+,R3
  375.        LDCR @B02,4
  376.        MOV  R3,*R1+
  377.        DECT R0
  378.        JNE  MKF31
  379.  
  380. * Check to see if the old file was protected
  381. *
  382.        MOVB @DFDR+12,R1      Get file flags
  383.        COC  @PROBIT,R1
  384.        JNE  MKF32
  385.  
  386.        LI   R1,1             File protect error
  387.        B    @MKFRT
  388.  
  389. MKF32
  390.  
  391. * If it is a program file, that is all we have to check.
  392. * Otherwise we must check DISPLAY/INTERNAL, FIXED/VARIABLE
  393. * and record length
  394.  
  395.        ANDI R1,>8000
  396.        JNE  MKF34A
  397.  
  398. * It's not a program file.  Make sure attributes match
  399. *
  400.        MOVB @DFDR+12,R1
  401.        ANDI R1,>C100
  402.        MOVB @MKFLAG,R2
  403.        ANDI R2,>C100
  404.        C    R1,R2
  405.        JEQ  MKF34
  406.  
  407. MKF33  LI   R1,7             File error
  408.        B    @MKFRT
  409.  
  410. MKF34
  411.  
  412. * Now check record length
  413.  
  414.        CB   @DFDR+17,@MKFRL
  415.        JNE  MKF33
  416.  
  417. * Everything checks out.  Lets rewrite a couple fields and
  418. * allocate some AUs!
  419. MKF34A
  420.        MOVB @MKFLAG,@DFDR+12     File flags
  421.        MOVB @MKFEOF,@DFDR+16     End Of File offset
  422.        MOV  @MKFL3,@DFDR+18      # of level 3 records
  423.  
  424. **
  425. *
  426. * Here we will allocate AU's if we need to
  427. *
  428. **
  429.  
  430. MKF40  MOV  @MKFSZ,R1        Get # of sectors wanted
  431.        LDCR @B04,4
  432.        MOV  R6,R3
  433.        SRL  R3,8
  434.        SLA  R3,1
  435.        MOV  @SAUTBL(R3),R3
  436.        A    R3,R1
  437.        DEC  R1
  438.        CLR  R0
  439.        DIV  R3,R0
  440.  
  441.  
  442.        MOV  R0,R8            R8 has # of AU's needed
  443.        LDCR @B02,4
  444.        C    R8,@DFDR+34      See if we need any more
  445.        JL   MKF44
  446.        JEQ  MKF44
  447.  
  448. * Ok - We need to allocate more AU's for this FDR!
  449. *
  450.        S    @DFDR+34,R8
  451.  
  452. MKF40A LI   R3,256*8         AU Boundry
  453.        CLR  R7               No preferred starting AU
  454.        LDCR @ZERO,4
  455.        BLWP @ALLOC
  456. *      JNE  MKFERR
  457.  
  458.        CI   R4,0
  459.        JNE  MKF41
  460.  
  461.        LI   R1,4             Out Of Space Error
  462.        B    @MKFRT
  463.  
  464. MKF41
  465. * Fill in the next cluster of the FDR
  466.        LI   R3,DFDR+40
  467.        LDCR @B02,4
  468. MKF42  C    *R3,@ZERO
  469.        JEQ  MKF43
  470.        AI   R3,4
  471.        JMP  MKF42
  472.  
  473. MKF43  MOV  R5,*R3+
  474.        MOV  R5,*R3
  475.        A    R4,*R3
  476.        DEC  *R3
  477.  
  478.        A    R4,@DFDR+34      Add to # of AUs allocated
  479.  
  480.        S    R4,R8            See if we need to get any more
  481.        JNE  MKF40A
  482.  
  483. MKF44
  484.  
  485. * Now lets fill in the # of sectors currently allocated.
  486. * For program files, this will be whatever the user wanted.
  487. * For data files, it is equal to the number of AU's
  488. * allocated time the number of sectors per AU.
  489. *
  490.        MOVB @DFDR+12,R1      Get file flags
  491.        ANDI R1,>0100
  492.        JNE  MKF45
  493.  
  494.        MOV  @DFDR+34,R1
  495.        MOV  R6,R3
  496.        SRL  R3,8
  497.        SLA  R3,1
  498.        LDCR @B04,4
  499.        MPY  @SAUTBL(R3),R1
  500.        LDCR @B02,4
  501.        MOV  R2,@DFDR+14
  502.        JMP  MKF46
  503.  
  504. MKF45  MOV  @MKFSZ,@DFDR+14
  505. MKF46
  506.  
  507. * All we have to do now is write the FDR back out to
  508. * disk and we're done!
  509.  
  510.        LDCR @B02,4
  511.        MOV  @MKFAU1,R7       Restore AU of FDR
  512.  
  513.        MOV  R6,R3
  514.        SRL  R3,8
  515.        SLA  R3,1
  516.        LDCR @B04,4
  517.        MPY  @SAUTBL(R3),R7
  518.        LI   R2,SECBUF
  519.        SRL  R8,1
  520.        JNC  MKF47
  521.        AI   R2,>100
  522. MKF47  SRL  R7,1
  523.        JNC  MKF48
  524.        AI   R8,>8000
  525. MKF48  LDCR @ZERO,4
  526.        BLWP @BANKIT
  527.        DATA SCSIRD           Read old block
  528. *      JNE  MKFERR
  529.  
  530.        LI   R1,DFDR
  531.        LI   R0,256
  532.  
  533. MKF49  LDCR @B02,4
  534.        MOV  *R1+,R4
  535.        LDCR @ZERO,4
  536.        MOV  R4,*R2+
  537.        DECT R0
  538.        JNE  MKF49
  539.  
  540.        BLWP @BANKIT          Write it back out
  541.        DATA SCSIWT
  542. *      JNE  MKFERR
  543.  
  544.        CLR  R1               Success!
  545.        B    @MKFRT
  546.